/**
 *******************************************************************************
 * TestFilter.java
 *
 * (c) Copyright 2009 YangYan
 *
 *＜所属工程名＞
 *  Test(事例工程)
 *＜功能概要＞
 *  用于验证用户是否存在的Servlet，该Servlet用于演示AJAX
 *＜作者＞
 *  杨砚
 *******************************************************************************
 */
package com.sanlian.servlet;


import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sanlian.entity.UserInfo;
import com.sanlian.service.UserManageService;

/**
 * 用于验证用户是否存在的Servlet，该Servlet用于演示AJAX
 * 
 *
 * @author 杨砚
 */
public class UserInfoChedkServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		UserManageService ums = new UserManageService();
		String userName = new String(req.getParameter("userName").getBytes("ISO-8859-1"),"GBK");
		UserInfo userInfo = ums.getUserInfoByUserName(userName);
		PrintWriter out = resp.getWriter();
		if(userInfo == null){
			out.print("您申请的用户名可以使用");
		}else{
			out.print("您申请的用户名已经存在，请换一个");
		}
		out.flush();
		out.close();
	}
}
